import { statisticsJupAotoTkNum } from "@Api/toolsApi"
// import { Button, Icon, Modal, Space } from "@bytedance/mona-ui"
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"

// import Coupon from "../../contents/jinritemai/componets/coupon"

// import { testGetConmpondata } from '@Api/compassApi/test'

interface TabsListType {
  title: string //标题
  icon: string //图标
  active: boolean //是否激活弹窗开关
  funcksy: string //点击事件
  drawerTtile?: string
  showPopoverStatus?: boolean
  actstr: string
  width?: number
}
export interface FuncTabs {
  tablist: [TabsListType]
}

export const AutoTk = createAsyncThunk(
  "functabs/AutoTk",
  async (_: any, { getState, dispatch }) => {
    statisticsJupAotoTkNum()
    open("https://fuwu.jinritemai.com/detail?service_id=22955 ")
  }
)
// 列表获取 后期异步获取数据 修改缓存
const funcTabs = createSlice({
  name: "funcTab",
  initialState: <any>{
    tablist: [
      //     {
      //     title: "限时限量购",
      //     active: false,
      //     funcksy: "ltlp",
      //     icon: 'TimeIcon'
      // },
      // {
      //     title: "拼团",
      //     active: false,
      //     funcksy: "groupBooking",
      //     icon: 'AdvertisingIcon'
      // },
      // {
      //     title: "优惠券",
      //     active: false,
      //     funcksy: "coupon",
      //     icon: 'CouponIcon'
      // }
      {
        title: "AI违规预检",
        active: false,
        funcksy: "AiWeiguiJianCe",
        icon: "AiDrawIcon",
        width: 1400,
        drawerTtile: "AI违规预检",
        showPopoverStatus: (() => {
          const dlyfundata: any = localStorage.getItem("dlyfundataee")
          const infoDate = {
            autoCoput: true
          }
          setTimeout((_) => {
            localStorage.setItem("dlyfundataee", JSON.stringify(infoDate))
          }, 200)
          try {
            const getJson = JSON.parse(dlyfundata)
            if (getJson.autoCoput) return false
          } catch (error) {
            return true
          }
          return true
        })()
      },

      {
        title: "商品裂变",
        active: false,
        funcksy: "shopCopy",
        icon: "PutAwayIcon"
      },
      {
        title: "限时限量购",
        active: false,
        funcksy: "LtaLp",
        icon: "CommodityIcon",
        drawerTtile: "限时限量购",
        actstr: "addCoupon",
        width: 1400
      },
      {
        title: "设置优惠券",
        active: false,
        funcksy: "coupon",
        icon: "CouponIcon",
        drawerTtile: "优惠券",
        actstr: "addCoupon",
        width: 1100
      },
      {
        title: "管理优惠券",
        active: false,
        funcksy: "coupon",
        icon: "CouponIcon",
        drawerTtile: "优惠券",
        actstr: "setCoupon",
        width: 1100
      },
      {
        title: "全自动阶梯券",
        active: false,
        funcksy: "coupon",
        icon: "CouponIcon",
        drawerTtile: "优惠券",
        actstr: "AutoSetCoupon",
        width: 1100
        // showPopoverStatus: (() => {
        //   const dlyfundata: any = localStorage.getItem("dlyfundata")
        //   const infoDate = {
        //     autoCoput: true
        //   }
        //   setTimeout((_) => {
        //     localStorage.setItem("dlyfundata", JSON.stringify(infoDate))
        //   }, 200)
        //   try {
        //     const getJson = JSON.parse(dlyfundata)
        //     if (getJson.autoCoput) return false
        //   } catch (error) {
        //     return true
        //   }
        //   return true
        // })()
      },
      {
        title: "清理无流量",
        active: false,
        funcksy: "clearNoFlow",
        icon: "DeleteIcon",
        width: 1200,
        drawerTtile: "清理无流量",
        hideFoolter: true
      },
      {
        title: "邀约达人",
        active: false,
        funcksy: "yaoyueDaren",
        icon: "CollectionIcon"
      },
      {
        title: "自动拍单",
        active: false,
        funcksy: "AutoTk",
        icon: "OrderExportIcon"
      },

      {
        title: "IP隔离",
        active: false,
        funcksy: "IpIsolation",
        icon: "OrderExportIcon"
      },
      {
        title: "ROI计算器",
        active: false,
        funcksy: "ROIcompute",
        icon: "RecoverIcon",
        modoSuatus: false,
        width: 800
      },
      {
        title: "商品优化",
        active: false,
        funcksy: "prodectOptimization",
        icon: "ClockwiseRotationIcon",
        drawerTtile: "商品优化",
        actstr: "repeatProdect",
        width: 1100,
        hideFoolter: true
      },
      //     {
      //        title: "新人礼金",
      //        active: false,
      //        funcksy: "newPerson",
      //        icon: 'CouponIcon',
      //        drawerTtile: '批量设置新人礼金'
      //    }

      , {
        title: "商品策略",
        active: false,
        funcksy: "shopConter",
        icon: "CouponIcon"
      },

    ],
    jianceGoodsId: ''
  },
  reducers: {
    ltlp: (state) => {
      state.tablist[0].active = true
    },
    groupBooking: (state) => {
      state.tablist[1].active = true
    },
    coupon: (state, action) => {
      state.tablist[action.payload].active = true
    },
    LtaLp: (state, action) => {
      state.tablist[action.payload].active = true
    },
    prodectOptimization: (state, action) => {
      state.tablist[action.payload].active = true
    },
    clearbox: (state, action) => {
      state.tablist.forEach((item) => {
        item.active = false
        item.modoSuatus = false
      })
    },
    setInfoData: (state) => {
      state.tablist = state.tablist.map((res: any) => {
        res.showPopoverStatus && (res.showPopoverStatus = false)
        return res
      })
    },
    ROIcompute: (state, action) => {
      console.log('actionactionaction', action)
      state.tablist[action.payload].modoSuatus = true
    },
    shopConter: (state, action) => {
      // state.tablist[3].active = true
      if (location.pathname === "/ffa/g/list") return
      window.location.href = "https://fxg.jinritemai.com/ffa/g/list"
    },
    shopCopy: (state, action) => {
      if (location.pathname === "/ffa/g/list") return
      window.location.href = "https://fxg.jinritemai.com/ffa/g/list"
    },
    IpIsolation: () => {
      open("https://doulingyang.cn/?Isolation=1")
    },
    // AutoTk: () => {
    //     statisticsJupAotoTkNum()
    //     open('https://fuwu.jinritemai.com/detail?service_id=22955 ')
    // },
    newPerson: (state, action) => {
      state.tablist[action.payload].active = true
    },

    AiWeiguiJianCe: (state, action) => {
      state.jianceGoodsId = ''
      state.tablist[action.payload].active = true
    },
    clearNoFlow: (state, action) => {
      state.tablist[action.payload].active = true
    },
    yaoyueDaren: (state, action) => {
      //   open("http://dly.doulingyang.cn/acl/invitation", "邀约达人")
    },
    clearFlowWeiStatus: (state, action) => {
      state.tablist.forEach((item) => {
        item.active = false
        item.funcksy === "clearNoFlow" && (item.active = action.payload)
      })
    },


    weiguijianceContent: (state, action) => {
      state.tablist.forEach(item => {
        if (item.funcksy == 'AiWeiguiJianCe') {
          item.active = true
        }
      })
      state.jianceGoodsId = action.payload
      console.log('action', action)
    }

  }
})

export const {
  ltlp,
  groupBooking,
  coupon,
  clearbox,
  shopConter,
  shopCopy,
  newPerson,
  setInfoData,
  clearNoFlow,
  yaoyueDaren,
  IpIsolation,
  LtaLp,
  ROIcompute,
  clearFlowWeiStatus,
  AiWeiguiJianCe,
  weiguijianceContent,
  prodectOptimization
} = funcTabs.actions
// export const { ltlp, groupBooking, coupon, clearbox, shopConter, shopCopy, newPerson, setInfoData, clearNoFlow, LtaLp } = funcTabs.actions

export default funcTabs.reducer
